package com.lagou.kudu;

import org.apache.kudu.client.*;

/**
 * @program: kuduHomework
 * @description:
 * @author: Mr.Wang
 * @create: 2021-03-05 12:24
 **/
public class Select {
	public static void main(String[] args) throws KuduException {
		//地址
		String masterAddr = "node01";
		//创建客户端连接
		KuduClient client = new KuduClient.KuduClientBuilder(masterAddr)
				.defaultSocketReadTimeoutMs(6000).build();

		try {
			//获取表对象
			KuduTable table = client.openTable("student");
			//创建scanner扫描
			KuduScanner scanner = client.newScannerBuilder(table).build();

			//遍历数据
			while(scanner.hasMoreRows()){
				for (RowResult rowResult : scanner.nextRows()){
					System.out.println(rowResult.getInt("id")
							+"\t"+rowResult.getString("name"));
				}
			}
		} catch (KuduException e) {
			e.printStackTrace();
		} finally {
			try {
				if (client != null) {
					client.close();
				}
			} catch (KuduException e) {
				e.printStackTrace();
			}
		}
	}
}
